using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class EventManager : SingleData<EventManager>
{
    private Dictionary<int, Action<object>> eventsDic;
    public void Init()
    {
        var enumValues = Enum.GetValues(typeof(EventType));
        eventsDic = new Dictionary<int, Action<object>>();
    }

    // ע���¼�
    public void AddListening(EventType enentType, Action<object> action)
    {
        int id = (int)enentType;
        AddListening(id, action);
    }

    public void AddListening(int id, Action<object> action)
    {
        Action<object> events;
        if (eventsDic.TryGetValue(id, out events))
        {
            events += action;
            eventsDic[id] = events;
        }
        else
        {
            events += action;
            eventsDic.Add(id, events);
        }
    }


    // ȡ��ע���¼�
    public void RemoveListening(EventType enentType, Action<object> action)
    {
        int id = (int)enentType;
        RemoveListening(id, action);
    }

    public void RemoveListening(int id, Action<object> action)
    {
        Action<object> events;

        if (eventsDic.TryGetValue(id, out events))
        {
            events -= action;
            eventsDic[id] = events;
        }
    }

    public void TriggerEvent(EventType enentType)
    {
        int id = (int)enentType;
        TriggerEvent(id);
    }

    public void TriggerEvent(int id,object data = null)
    {
        Action<object> events;
        if (eventsDic.TryGetValue(id, out events))
        {
            events?.Invoke(data);
        }
    }
}


public enum EventType { 



}

